<div class="users form">
<?php e($form->create('User', array('action' => 'password')));?>
    <fieldset>
        <legend><?php __('Change Password');?></legend>
        <?php e($form->input('newpassword', array(
                            'label'=>__('New password(at least 6 characters)', true),
                            'type'=>'password',
                            'class' => 'password input'))); ?>
        <?php e($form->input('newpasswordconfirm', array(
                            'label'=>__('Confirm new password', true),
                            'type'=>'password',
                            'class' => 'password input'))) ?>
        <?php e($form->submit(__('Save Changes', true), array('type'=>'submit', 'class' => 'submit'))); ?>
    </fieldset>
<?php e($form->end()); ?>
</div>
<script type="text/javascript">
$(window).ready(function(){
    $('div#menu').mousemove();
    // Validate Change password form
    var rules = {
        required: true,
        minlength: 6
    };
    if($('#UserPasswordForm').length){
        $.log('Validate UserPasswordForm');
        $('#UserPasswordForm').clearForm().validate({
            success: function(label){
                label.nextAll('label.success').remove();
                label.attr('class', 'success').html('Good').prev('input').addClass('success');
            },
            rules: {
                'data[User][newpassword]': rules,
                'data[User][newpasswordconfirm]': rules
            },
            messages: {
                'data[User][newpassword]': {
                    required: '请不要将新密码设置为空值',
                    minlength: '密码长度应该在6位以上, 保证您的账户安全'
                },
                'data[User][newpasswordconfirm]': {
                    required: '确认密码应该和新密码相同',
                    minlength: '密码长度应该在6位以上, 保证您的账户安全'
                }
            }
        });
        $('#UserPasswordForm input.submit').click(function(event){
            //event.preventDefault();
            if(!$('#UserPasswordForm').valid()){
                $.log('Submit Empty values, drop the request');
                return false;
            }
            if($('input#UserNewpassword').val() != $('input#UserNewpasswordconfirm').val()){
                $.log('Submit with different passwords, drop the request');
                alert('两次输入的密码不一致');
                return false;
            }
        });
    }
});
</script>